package com.cssw.fyzb.core.dao.tesk;


import com.cssw.fyzb.core.model.dodb.Task;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.util.HashMap;

import java.util.Map;

/**
 * @author
 */
@Repository
public class TaskDaoImpl implements TaskDao {

    @Override
    public Page<Task> taskList(Long userId, int pageNumber, int pageSize) {
        Map<String, Object> param = new HashMap<>();
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select * from d_task   ");
        return Task.dao.paginate(pageNumber, pageSize, sqlParse);
    }

    @Override
    public Page<Task> oldList(Long userId, String status, int pageNumber, int pageSize) {
        Map<String, Object> param = new HashMap<>();
        param.put("userId", userId);
        param.put("status", status);
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select t1.*,t2.create_time,t2.surplus_value,t2.all_value from d_task t1 left join  t_rule_inst t2 on t1.task_id=t2.task_id ");
        sqlParse.addSQL("  where user_id=:userId and status=:status");
        return Task.dao.paginate(pageNumber, pageSize, sqlParse);
    }

    @Override
    public Task getTask(Long taskId) {
        return Task.dao.findById(taskId);
    }


}
